package hidalgo.expenses.widgets;

import hidalgo.expenses.R;
import hidalgo.expenses.entities.Account;
import hidalgo.expenses.utils.Util;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class AccountItemView extends RelativeLayout {

	private TextView txtName;
	private TextView txtTotal;
	private Account account;

	public AccountItemView(Context context, Account account) {
		super(context);
		inflateLayout(context);
		setAccount(account);

	}

	public AccountItemView(Context context) {
		super(context);
		inflateLayout(context);

	}

	public AccountItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		inflateLayout(context);

	}

	private void inflateLayout(Context context) {
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = layoutInflater.inflate(R.layout.account_item, this);

		this.txtName = (TextView) view.findViewById(R.id.txtName);
		this.txtTotal = (TextView) view.findViewById(R.id.txtTotal);
	}

	public void setAccount(Account account) {
		this.account = account;

		if (account != null) {

			txtName.setText(account.getName());
			txtTotal.setText(Util.moneyFormat.format(account.getTotal()));
		}
	}

	public Account getAccount() {
		return account;
	}

}
